home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Games / Quinto / Source / Quinto.m < prev   
Text File  |  1992-09-27  |  3KB  |  130 lines

  1. /*  Quinto.m
  2.  * Copyright Edmund Ronald 1991.
  3.  * This source code, may be duplicated and distributed 
  4.  *  by anyone, provided  that the icon er.tiff and makefile are distributed together with any copy .
  5.  */
  6.  
  7. #import <appkit/appkit.h> // the kitchen sink?
  8.  
  9. id  theArray[5][5];
  10.  
  11. @interface MyView:View
  12. - ButtonClicked:sender;
  13. - newGame;
  14. @end
  15.  
  16. @implementation MyView
  17. - newGame
  18. { int i, j;
  19.   for(i=0; i<5; i++) for(j=0; j<5; j++) [theArray[i][j] setState:0];
  20.   return self;
  21. }
  22.  
  23. - ButtonClicked:sender
  24. {  int i,j,t;
  25.    t= [sender tag];
  26.    j = t/5;
  27.    i = t % 5;
  28.   
  29.   if(i>0) [(theArray[i-1][j]) setState:![(theArray[i-1][j])state]];
  30.   if(i<4) [(theArray[i+1][j]) setState:![(theArray[i+1][j])state]];
  31.   if(j>0) [(theArray[i][j-1]) setState:![(theArray[i][j-1])state]];
  32.   if(j<4) [(theArray[i][j+1]) setState:![(theArray[i][j+1])state]];
  33.      
  34.    return self;
  35. }
  36. @end
  37.  
  38. void setUp(void)
  39. {
  40.     id     myWindow, myPanel, myMenu, windowText, myButton, theView;
  41.     NXRect     aRect;
  42.     int i,j,t;
  43.     
  44.     // set up main window
  45.     NXSetRect(&aRect, 100.0, 100.0, 210.0, 210.0); // location, extent
  46.     myWindow = [[Window alloc] initContent:&aRect
  47.                     style:NX_TITLEDSTYLE
  48.                     backing:NX_BUFFERED
  49.                     buttonMask:NX_MINIATURIZEBUTTONMASK
  50.                     defer:NO];
  51.     [myWindow setTitle:"QUINTO 1.0"];
  52.         
  53.     // set up a subview
  54.         NXSetRect(&aRect, 0.0, 0.0, 210.0, 210.0);
  55.     theView = [[MyView alloc] initFrame:&aRect];
  56.         [[myWindow contentView] addSubview:theView];
  57.     
  58.      //set up the buttons in the subview
  59.     j=0;
  60.     while(j<5) { i=0;  while(i<5){
  61.         NXSetRect(&aRect,i*30.0+30.0, j*30.0+30.0, 30.0, 30.0);
  62.             myButton =  [[Button alloc] initFrame:&aRect] ;     
  63.            t=(5*j +i);
  64.         [myButton setTag:t ];
  65.         [myButton setTarget:theView];
  66.         [myButton setAction:@selector(ButtonClicked:)];
  67.             [myButton setType:NX_PUSHONPUSHOFF ];                                                                                                                                        
  68.         [theView addSubview:myButton];
  69.         theArray[i][j] = myButton;
  70.          i++;}  j++;}
  71.  
  72.     //set up info text
  73.     NXSetRect(&aRect, 0.0, 0.0, 400.0, 200.0);
  74.     windowText = [[Text alloc] initFrame:&aRect
  75.                     text:"\nCopyright Edmund Ronald 1991\n"
  76.                     "Use and distribute freely for non-commercial purposes\n"
  77.                     "but do not change copyright or program name\n"
  78.                     "NO WARRANTY WHATSOEVER\n\n"
  79.                     "eronald@cnam.cnam.fr\n"
  80.                     "\n"
  81.                     "AIM OF GAME: HILITE ALL BUTTONS\n *IT’S POSSIBLE*" 
  82.                      alignment:NX_CENTERED];
  83.     [windowText setOpaque:YES];
  84.     
  85.     //set up info panel
  86.     NXSetRect(&aRect, 200.0, 500.0, 400.0, 200.0);
  87.     myPanel = [[Panel alloc] initContent:&aRect
  88.                     style:NX_TITLEDSTYLE
  89.                     backing:NX_BUFFERED
  90.                     buttonMask:NX_CLOSEBUTTONMASK
  91.                     defer:YES];
  92.     [myPanel setTitle:"About Quinto"];
  93.     [[myPanel contentView] addSubview:windowText];
  94.         [myPanel removeFromEventMask:(NX_KEYDOWNMASK | NX_KEYUPMASK)];
  95.  
  96.  
  97.     myMenu = [[Menu alloc] initTitle:"Quinto"];
  98.     [[myMenu addItem:"Info..."
  99.             action:@selector(orderFront:)
  100.             keyEquivalent:'\0']
  101.                 setTarget:myPanel];
  102.     [[myMenu addItem:"New Game"
  103.             action:@selector(newGame)
  104.             keyEquivalent:'n']
  105.                 setTarget:theView];            
  106.     [myMenu addItem:"Hide"
  107.             action:@selector(hide:)
  108.             keyEquivalent:'h'];
  109.     [myMenu addItem:"Quit"
  110.             action:@selector(terminate:)
  111.             keyEquivalent:'q'];
  112.     [myMenu sizeToFit];
  113.     [NXApp setMainMenu:myMenu];
  114.  
  115.  
  116.     [myWindow display];
  117.     [myWindow orderFront:nil];
  118.     [myWindow makeKeyWindow];
  119. }
  120.  
  121.  
  122. int main()
  123. {
  124.     [Application new];
  125.     setUp();
  126.     [NXApp run];
  127.     [NXApp free];
  128.     return 0;
  129. }
  130.